<script language="JavaScript" src="/framework/highcharts/js/highcharts.js" type="text/javascript"></script>
<script language="JavaScript" src="/framework/highcharts/js/modules/exporting.js" type="text/javascript"></script>
<script>
	//饼图对象
	var pieObj = {
		
		chart: {
			renderTo: '',
			defaultSeriesType: 'pie'
		},
		title: {
			text: ''
		},
		tooltip: {
			formatter:function(){}
        },
		plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>';
                    }
                },
                showInLegend: true,
				events: {
					click: function(obj){
						if (obj.point.newUrl){
							window.open(obj.point.newUrl);
						}else if(obj.point.selfUrl){
							window.location = obj.point.selfUrl;
						}else if(obj.point.smalUrl){
							E.open(obj.point.smalUrl);
						}
					}
				}
            }
        },
		credits: {
             text: '',
             href: ''
         },
		series: [{
            type: 'pie',
            name: '',
            data: {}
        }]
	};
	
	//柱图对象
	var columnObj = {
        chart: {
            renderTo: '',
            defaultSeriesType: 'column'
        },
        title: {
            text: ''
        },
        xAxis: {
            categories: []
        },
        tooltip: {
            shared: true,
            useHTML: true
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        credits: {
            text: '',
            href: ''
        },
        series: []
    };
	
	//横条图对象
	var barObj = {
        chart: {
            renderTo: '',
            defaultSeriesType: 'bar'
        },
        title: {
            text: ''
        },
        xAxis: {
            categories: []
        },
        tooltip: {
            shared: true,
            useHTML: true
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        credits: {
            text: '',
            href: ''
        },
        series: []
    };
	
	
	/*
	 * 绘制饼图
	 * @param {Object} data			该图表的数据
	 * @param {String} rendto		该图表绘制的位置（div对应的ID）
	 * @param {String} titleText	该图表的表头
	 */
	function drawPie (data, rendto, titleText){
		//第一个饼图
		var pieName = $.extend({}, pieObj, {
			chart: {
				renderTo: rendto,
				defaultSeriesType: 'pie'
			},
			title: {
				text: titleText
			},
			tooltip: {
				formatter:function(){
					return'<b>'+this.point.name+'</b>: '+ this.point.y + this.point.unit + '<br/><b>占比：</b>' + twoDecimal(this.percentage) +' %';
				}
	        },
			series: [{
	            type: 'pie',
	            name: '',
	            data: data
	        }]
		});
		
		new Highcharts.Chart(pieName);
	}
	
	/*
	 * 绘制柱图
	 * @param {Object} data			该图表的数据
	 * @param {String} rendto		该图表绘制的位置（div对应的ID）
	 * @param {String} titleText	该图表的表头
	 */
	function drawColumn (data, rendto, titleText){
		//第一个饼图
		var columnName = $.extend({}, columnObj, {
			chart: {
				renderTo: rendto,
				defaultSeriesType: 'column'
			},
			title: {
				text: titleText
			},
			xAxis: {
	            categories: data.xData
	        },
	        yAxis:data.yData,
			series: data.sData
		});
		
		new Highcharts.Chart(columnName);
	}
	
	/*
	 * 绘制横条图
	 * @param {Object} data			该图表的数据
	 * @param {String} rendto		该图表绘制的位置（div对应的ID）
	 * @param {String} titleText	该图表的表头
	 */
	function drawBar (data, rendto, titleText){
		
		var barName = $.extend({}, barObj, {
			chart: {
				renderTo: rendto,
				defaultSeriesType: 'bar'
			},
			title: {
				text: titleText
			},
			xAxis: {
	            categories: data.xData
	        },
			series: data.sData
		});
		
		new Highcharts.Chart(barName);
	}
	
	//保留2位小数
	function twoDecimal(x) {
	    var f_x = parseFloat(x);
	    if (isNaN(f_x)) {
	        alert('错误的参数');
	        return false;
	    }
	    var f_x = Math.round(x * 100) / 100;
	    var s_x = f_x.toString();
	    var pos_decimal = s_x.indexOf('.');
	    if (pos_decimal < 0) {
	        pos_decimal = s_x.length;
	        s_x += '.';
	    }
	    while (s_x.length <= pos_decimal + 2) {
	        s_x += '0';
	    }
	    return s_x;
	}
</script>